package com.sywb.chuangyebao.contract;

import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.sywb.chuangyebao.Constants;
import com.sywb.chuangyebao.bean.AlipayWeiXinIsBoundBean;
import com.sywb.chuangyebao.bean.AlipayWxWithDrawBean;
import com.sywb.chuangyebao.utils.HttpCallback;
import com.sywb.chuangyebao.utils.HttpUtils;
import com.sywb.chuangyebao.view.AlipayWithdrawActivity;
import com.sywb.chuangyebao.view.WeiXinWithdrawActivity;
import com.tencent.mm.opensdk.modelmsg.SendAuth;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

import org.bining.footstone.mvp.IFragment;
import org.bining.footstone.mvp.IView;
import org.bining.footstone.presenter.BasePresenter;
import org.bining.footstone.rxjava.rxbus.RxBus;
import org.bining.footstone.utils.SharedUtils;

public interface WithDrawContract {
   interface WithDrawView extends IView{

   }

   class WithDrawPresenter extends BasePresenter<WithDrawView>{

       @Override
       public void onStart() {

       }

       /**
        * 绑定微信获取信息
        */
       public void bindingWeiXin(String code) {
            HttpUtils.bindWeiXin(code, new HttpCallback<String>() {
                @Override
                public void onSuccess(String s) {
                    //绑定成功以后直接跳转到微信提现页面
                    mView.advance(WeiXinWithdrawActivity.class);
                }

                @Override
                public void onFinish() {
                    super.onFinish();
                }

                @Override
                public void onError(String strMsg) {
                    super.onError(strMsg);
                    showMessage("绑定失败");
                }
            });
       }

        public void alipayWeiXinIsBound(){
           HttpUtils.alipayWeiXinIsBound(new HttpCallback<AlipayWeiXinIsBoundBean>() {
               @Override
               public void onSuccess(AlipayWeiXinIsBoundBean alipayWeiXinIsBoundBean) {
                   RxBus.get().post(Constants.POST_ALIPAY_WEIXIN_IS_BOUND,alipayWeiXinIsBoundBean);
               }

               @Override
               public void onError(String strMsg) {
                   super.onError(strMsg);
                   showMessage(strMsg);
               }
           });
        }
       /**
        * 微信登录授权
        */
       public void clickBtnWeinxinLogin() {
           // 通过WXAPIFactory工厂，获取IWXAPI的实例
           IWXAPI api = WXAPIFactory.createWXAPI(mContext, Constants.WEIXIN_APPID, false);
           // 将该app注册到微信
           api.registerApp(Constants.WEIXIN_APPID);

           //发起登录请求
           SendAuth.Req req = new SendAuth.Req();
           req.scope = "snsapi_userinfo";
           req.state = "wechat_sdk_CYB";
           api.sendReq(req);
       }
   }
}
